package Test;

import static org.junit.Assert.*;

import java.util.LinkedList;

import leducHoldem.Data.Move;
import leducHoldem.misc.CFRInformationSet;

import org.junit.Test;

public class InformationSetTest {

	@Test
	public void valuesTestWithMoves() {
		
		LinkedList<Move> moves = new LinkedList<Move>();
		
		moves.add(new Move("b"));
		moves.add(new Move("ch"));
		
		CFRInformationSet set = new CFRInformationSet(moves, (byte)1, new Move("J"));
		
		set.setValueForCardOnIndex(new Move("J"), 0, 15);
		set.setValueForCardOnIndex(new Move("J"), 1, -15);
		
		set.setValueForCardOnIndex(new Move("K"), 0, 14);
		set.setValueForCardOnIndex(new Move("K"), 1, -14);
		
		float[] valuesForJ = new float[]{15, -15};
		float[] valuesForK = new float[]{14, -14};
		
		for (int i = 0; i < valuesForK.length; i++) {
			assertEquals(valuesForK[i], set.getValuesForCard(new Move("K"))[i], 0.00001);
		}
		
		for (int i = 0; i < valuesForK.length; i++) {
			assertEquals(valuesForJ[i], set.getValuesForCard(new Move("J"))[i], 0.00001);
		}
		
		for (int i = 0; i < valuesForK.length; i++) {
			assertEquals(0, set.getValuesForCard(new Move("Q"))[i], 0.00001);
		}
	}
	
	@Test
	public void valuesTestWithIndexes() {
		
		LinkedList<Move> moves = new LinkedList<Move>();
		
		moves.add(new Move("b"));
		moves.add(new Move("ch"));
		
		CFRInformationSet set = new CFRInformationSet(moves, (byte)1, new Move("J"));
		
		set.setValueForIndexes(0, 0, 15);
		set.setValueForIndexes(0, 1, -15);
		
		set.setValueForIndexes(2, 0, 14);
		set.setValueForIndexes(2, 1, -14);
		
		float[] valuesForJ = new float[]{15, -15};
		float[] valuesForK = new float[]{14, -14};
		
		for (int i = 0; i < valuesForK.length; i++) {
			assertEquals(valuesForK[i], set.getValuesOnIndex(2)[i], 0.00001);
		}
		
		for (int i = 0; i < valuesForK.length; i++) {
			assertEquals(valuesForJ[i], set.getValuesOnIndex(0)[i], 0.00001);
		}
		
		for (int i = 0; i < valuesForK.length; i++) {
			assertEquals(0, set.getValuesOnIndex(1)[i], 0.00001);
		}
	}
	
	@Test
	public void addValuesToMoveTest() {
		
		LinkedList<Move> moves = new LinkedList<Move>();
		
		moves.add(new Move("b"));
		moves.add(new Move("ch"));
		
		CFRInformationSet set = new CFRInformationSet(moves, (byte)1, new Move("J"));
		
		float[] valuesForBet = new float[]{12, -12, -1};
		
		set.addValuesForMove(0, valuesForBet);
		
		float[][] expectedValues = new float[][]{{12, 0}, {-12, 0}, {-1, 0}};
		
		for (int i = 0; i < expectedValues.length; i++) {
			for (int j = 0; j < expectedValues[0].length; j++) {
				assertEquals(expectedValues[i][j], set.getValuesOnIndex(i)[j], 0.001);
			}
		}
	}

}
